package com.ruoyi.web.controller.datastatistics;

import java.text.ParseException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.datastatistics.vo.DayOrMonthDosageStatistics;
import com.ruoyi.datastatistics.vo.DayOrMonthDosageStatisticsBill;
import com.ruoyi.datastatistics.vo.XbStatisticAnalysisReq;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.datastatistics.domain.BillDetail;
import com.ruoyi.datastatistics.service.IBillDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 开账明细Controller
 *
 * @author zt
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/datastatistics/billDetail")
public class BillDetailController extends BaseController
{
    @Autowired
    private IBillDetailService billDetailService;



    /**
     * 查询开账明细列表
     */
    @GetMapping("/getBillDetailDosageList")
    public TableDataInfo getBillDetailDosageList(XbStatisticAnalysisReq req)
    {
        startPage();
        List<DayOrMonthDosageStatisticsBill> list = billDetailService.selectBillDetailList(req);
        return getDataTable(list);
    }


    @PostMapping("/exportBillDetailDosageList")
    public void exportBillDetailDosageList(HttpServletResponse response, XbStatisticAnalysisReq req) throws ParseException {
        List<DayOrMonthDosageStatisticsBill> list = billDetailService.selectBillDetailList(req);
        ExcelUtil<DayOrMonthDosageStatisticsBill> util = new ExcelUtil<DayOrMonthDosageStatisticsBill>
                (DayOrMonthDosageStatisticsBill.class);
        util.exportExcel(response, list, "用户用量统计");
    }





    /**
     * 查询开账明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BillDetail billDetail)
    {
        startPage();
        List<BillDetail> list = billDetailService.selectBillDetailList(billDetail);
        return getDataTable(list);
    }

    /**
     * 导出开账明细列表
     */
    @Log(title = "开账明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillDetail billDetail)
    {
        List<BillDetail> list = billDetailService.selectBillDetailList(billDetail);
        ExcelUtil<BillDetail> util = new ExcelUtil<BillDetail>(BillDetail.class);
        util.exportExcel(response, list, "开账明细数据");
    }

    /**
     * 获取开账明细详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(billDetailService.selectBillDetailById(id));
    }

    /**
     * 新增开账明细
     */
    @Log(title = "开账明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillDetail billDetail)
    {
        return toAjax(billDetailService.insertBillDetail(billDetail));
    }

    /**
     * 修改开账明细
     */
    @Log(title = "开账明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillDetail billDetail)
    {
        return toAjax(billDetailService.updateBillDetail(billDetail));
    }

    /**
     * 删除开账明细
     */
    @Log(title = "开账明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(billDetailService.deleteBillDetailByIds(ids));
    }
}
